package com.situ.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.Order;
import com.situ.crm.service.IOrderService;

@Controller
@RequestMapping(value="/order")
public class OrderController {
	@Autowired
	private IOrderService orderService;
	
	@RequestMapping(value="/getOrderPage")
	public String getOrder() {
		return "order/order_list";
	}
	
	//分页
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Order order) {
		ServerResponse serverResponse = orderService.pageList(page,limit,order);
		System.err.println(serverResponse.getData());
		return serverResponse;
	}
	
	//添加页面
	@RequestMapping(value="/getAddPage")
	public String getAddPage() {
		return "order/order_insert";
	}
	
	//添加功能
	@RequestMapping(value="/insert")
	@ResponseBody
	public ServerResponse insert(Order order) {
		return orderService.insert(order);
	}
	
	//删除功能
	@RequestMapping(value="/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return orderService.deleteById(id);
	}
	
	//批量删除
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return orderService.deleteAll(ids);
	}
	
	//修改页面
    @RequestMapping(value="getUpdatePage")
	public String getUpdatePage(Integer id,Model model) {
    	Order order = orderService.select(id);
    	model.addAttribute("order",order);
		return "order/order_update";
	}
    
    //修改
    @RequestMapping(value="/update")
    @ResponseBody
    public ServerResponse update(Order order) {
    	System.err.println(order);
		return orderService.update(order);
	}
	
	//EChars统计销量
    @RequestMapping(value="/getOrderCountPage")
    public String getOrderCountPage() {
		return "order/order_count";
	}
    
    @RequestMapping(value="/orderCount")
    @ResponseBody
    public ServerResponse orderCount() {
		return orderService.selectOrderCount();
	}
}
